#include <iostream>

using namespace std;

class Tools {
public:
    virtual void doSomeThing() = 0;
};

class CommonTools : public Tools {
public:
    void doSomeThing() override {
        cout << "Common Tools Do Some Thing!" << endl;
    }
};

class SpecialTools {
public :
    void doSomeThing() {
        cout << "Special Tools Do Some Thing!" << endl;
    }
};

// 通过双继承实现适配器模式
class Adapter1 : public Tools, SpecialTools {
public:
    void doSomeThing() override {
        SpecialTools::doSomeThing();
    }
};

// 通过类之间的组合实现适配器模式
class Adapter2 : public Tools {
public:
    Adapter2(SpecialTools *instance) : instance(instance) {}

    virtual ~Adapter2() {
        delete instance;
    }

private:
    SpecialTools *instance = nullptr;

public:
    void doSomeThing() override {
        instance->doSomeThing();
    }
};

void test01() {
    Tools *tools = nullptr;

    tools = new CommonTools();
    tools->doSomeThing();
    delete tools;

    tools = new Adapter1();
    tools->doSomeThing();
    delete tools;

    cout << endl;
}

void test02() {
    Tools *tools = nullptr;

    tools = new CommonTools();
    tools->doSomeThing();
    delete tools;

    tools = new Adapter2(new SpecialTools());
    tools->doSomeThing();
    delete tools;

    cout << endl;
}

int main() {
    test01();

    test02();
}